#define _CRT_SECURE_NO_WARNINGS 1/**
*      author: Y_Yao
*      created: 2024-10-25 12:02:33
**/

#include<bits/stdc++.h>

using namespace std;
#define int LL
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 500 + 7;
int a[N][N];
int n;
int mx[2 * N];

void solve()
{
    cin >> n;
    memset(mx, LLINF, sizeof mx);
    for (int i = 1;i <= n;i++)
    {
        for (int j = 1;j <= n;j++)
        {
            cin >> a[i][j];
            if (a[i][j] < 0 && a[i][j] < mx[j - i + n])
            {
                mx[j - i + n] = a[i][j];
            }
        }
    }

    int ret = 0;
    for (int i = 1;i <= 2 * n;i++)
    {
        if (mx[i] != LLINF) ret += abs(mx[i]);
    }

    cout << ret << endl;

}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}